home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2004 April / Gamestar_61_2004-04_dvdb.iso / DVDStar / Editace / hltp.exe / {app} / Source Code / Half-Life Model Viewer / src / mathlib.h < prev    next >
C/C++ Source or Header  |  1999-05-04  |  3KB  |  90 lines

  1. /***
  2. *
  3. *    Copyright (c) 1998, Valve LLC. All rights reserved.
  4. *    
  5. *    This product contains software technology licensed from Id 
  6. *    Software, Inc. ("Id Technology").  Id Technology (c) 1996 Id Software, Inc. 
  7. *    All Rights Reserved.
  8. *
  9. ****/
  10.  
  11. #ifndef __MATHLIB__
  12. #define __MATHLIB__
  13.  
  14. // mathlib.h
  15.  
  16. #include <math.h>
  17.  
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21.  
  22. #ifdef DOUBLEVEC_T
  23. typedef double vec_t;
  24. #else
  25. typedef float vec_t;
  26. #endif
  27. typedef vec_t vec3_t[3];    // x,y,z
  28. typedef vec_t vec4_t[4];    // x,y,z,w
  29.  
  30. #define    SIDE_FRONT        0
  31. #define    SIDE_ON            2
  32. #define    SIDE_BACK        1
  33. #define    SIDE_CROSS        -2
  34.  
  35. #define    Q_PI    3.14159265358979323846
  36.  
  37. extern vec3_t vec3_origin;
  38.  
  39. // Use this definition globally
  40. #define    ON_EPSILON        0.01
  41. #define    EQUAL_EPSILON    0.001
  42.  
  43. int VectorCompare (vec3_t v1, vec3_t v2);
  44.  
  45. #define DotProduct(x,y) ((x)[0]*(y)[0]+(x)[1]*(y)[1]+(x)[2]*(y)[2])
  46. #define VectorFill(a,b) { (a)[0]=(b); (a)[1]=(b); (a)[2]=(b);}
  47. #define VectorAvg(a) ( ( (a)[0] + (a)[1] + (a)[2] ) / 3 )
  48. #define VectorSubtract(a,b,c) {(c)[0]=(a)[0]-(b)[0];(c)[1]=(a)[1]-(b)[1];(c)[2]=(a)[2]-(b)[2];}
  49. #define VectorAdd(a,b,c) {(c)[0]=(a)[0]+(b)[0];(c)[1]=(a)[1]+(b)[1];(c)[2]=(a)[2]+(b)[2];}
  50. #define VectorCopy(a,b) {(b)[0]=(a)[0];(b)[1]=(a)[1];(b)[2]=(a)[2];}
  51. #define VectorScale(a,b,c) {(c)[0]=(b)*(a)[0];(c)[1]=(b)*(a)[1];(c)[2]=(b)*(a)[2];}
  52.  
  53. vec_t Q_rint (vec_t in);
  54. vec_t _DotProduct (vec3_t v1, vec3_t v2);
  55. void _VectorSubtract (vec3_t va, vec3_t vb, vec3_t out);
  56. void _VectorAdd (vec3_t va, vec3_t vb, vec3_t out);
  57. void _VectorCopy (vec3_t in, vec3_t out);
  58. void _VectorScale (vec3_t v, vec_t scale, vec3_t out);
  59.  
  60. double VectorLength(vec3_t v);
  61.  
  62. void VectorMA (vec3_t va, double scale, vec3_t vb, vec3_t vc);
  63.  
  64. void CrossProduct (vec3_t v1, vec3_t v2, vec3_t cross);
  65. vec_t VectorNormalize (vec3_t v);
  66. void VectorInverse (vec3_t v);
  67.  
  68. void ClearBounds (vec3_t mins, vec3_t maxs);
  69. void AddPointToBounds (vec3_t v, vec3_t mins, vec3_t maxs);
  70.  
  71. void AngleMatrix (const vec3_t angles, float matrix[3][4] );
  72. void AngleIMatrix (const vec3_t angles, float matrix[3][4] );
  73. void R_ConcatTransforms (const float in1[3][4], const float in2[3][4], float out[3][4]);
  74.  
  75. void VectorIRotate (const vec3_t in1, const float in2[3][4], vec3_t out);
  76. void VectorRotate (const vec3_t in1, const float in2[3][4], vec3_t out);
  77.  
  78. void VectorTransform (const vec3_t in1, const float in2[3][4], vec3_t out);
  79.  
  80. void AngleQuaternion( const vec3_t angles, vec4_t quaternion );
  81. void QuaternionMatrix( const vec4_t quaternion, float (*matrix)[4] );
  82. void QuaternionSlerp( const vec4_t p, vec4_t q, float t, vec4_t qt );
  83.  
  84.  
  85. #ifdef __cplusplus
  86. }
  87. #endif
  88.  
  89. #endif
  90.